package day08.difference;

import org.junit.Test;

/**
 * @Auther: sky
 * @Date: 2019/3/5 22:58
 * @Description:
 */
public class Run {

    public static void main(String[] args) {
        Task task = new Task();

        MyThread1 thread1 = new MyThread1(task);
        thread1.start();

        MyThread2 thread2 = new MyThread2(task);
        thread2.start();

        try {
            //主要是为了暂停当前线程，把cpu片段让出给其他线程，减缓当前线程的执行
            Thread.sleep(20000);//Thread类的方法,只对当前线程起作用,睡眠一段时间
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        long beginTime = CommonUtils.beginTime1;
        if (CommonUtils.beginTime2 < CommonUtils.beginTime1) {
            beginTime = CommonUtils.beginTime2;
        }

        long endTime = CommonUtils.endTime1;
        if (CommonUtils.endTime2 > CommonUtils.endTime1) {
            endTime = CommonUtils.endTime2;
        }

        System.out.println("耗时" + ((endTime - beginTime) / 1000));
    }


    @Test
    public void getDif()throws Exception{
        ClassSyncLock classSyncLock =new ClassSyncLock();
        MyThread3 myThread3 = new MyThread3(classSyncLock);
        MyThread4 myThread4 = new MyThread4(classSyncLock);

        myThread3.start();
        myThread4.start();

        Thread.sleep(10000);
    }


}
